home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nannws22.zip / BMOUSE.ASM next >
Assembly Source File  |  1987-12-08  |  16KB  |  440 lines

  1. ;*******************************************
  2. ;* Filename..............:BMOUSE.asm
  3. ;*------------------------------------------
  4. ;* PART I - Adapted from.: PC Magazine, Vol.6 No.13; July 21,1987
  5. ;*                         Article: MOUSE SOFTWARE by Jeff Prosise
  6. ;* Modified by...........: Bao Hoang
  7. ;* Date..................: August 1987
  8. ;*
  9. ;* Syntax.......: memvar = M_SET_ON()
  10. ;*              : memvar = M_SET_OFF()
  11. ;*
  12. ;* Return values: M_SET_ON()  - .T. if everything is O.K. and .F.
  13. ;*                              if something is wrong (i.e., 
  14. ;*                              mouse driver not installed)
  15. ;*                M_SET_OFF() - always returns .T. and return
  16. ;*                              value can pretty much be ignored
  17. ;*
  18. ;*                CSR_ON()    - .T. if everything is O.K. and .F.
  19. ;*                              if it was not able to install the
  20. ;*                              routine (i.e., mouse driver not
  21. ;*                              installed)
  22. ;*
  23. ;*                CSR_OFF()    - always returns a .T.
  24. ;*
  25. ;*******************************************
  26.  
  27.  
  28. ;*** declare callable routines as PUBLIC
  29. ;
  30.      public M_SET_ON
  31.      public M_SET_OFF
  32.      public CSR_ON
  33.      public CSR_OFF
  34.      public LD_SCR
  35.  
  36. ;*** declare Clipper's procedures for returning variables as FAR
  37. ;
  38.      extrn          __RETL:far    ; returns logical type
  39.      extrn          __PARNI:far
  40.  
  41. ;*** define keys to insert based on mouse conditions.
  42. ;
  43.      LB             equ 1C0Dh     ; set LEFT button to RETURN key
  44.      CB             equ 3B00h     ; set CENTER button to F1 key
  45.      RB             equ 011Bh     ; set RIGHT button to ESC key
  46.  
  47.  
  48. ;*** Define keyboard buffer area.
  49. ;
  50. BIOS_DATA segment at 40h
  51.      org                 1ah
  52.      BUFFER_HEAD         dw   ?   ;pointer to the keybord
  53.                                   ;buffer head
  54.      BUFFER_TAIL         dw   ?   ;pointer to the keyboard
  55.                                   ;buffer tail
  56.      org                 80h
  57.      BUFFER_START        dw   ? ;starting keyboard buffer address
  58.      BUFFER_END          dw   ? ;ending keyboard buffer address
  59. BIOS_DATA ends
  60. ;
  61. ;
  62. ;
  63. CODE segment 'CODE'         ; declare code segment of class CODE
  64.     assume cs:CODE,ds:BIOS_DATA
  65.  
  66.     VCOUNT         db   10        ; vertical delay counter
  67.     HCOUNT         db   10        ; horizontal delay counter
  68.     HFLAG          dw   ?         ; horizontal count sign flag
  69.     VFLAG          dw   ?         ; vertical count sign flag
  70.     KEYCODE        db   4Dh,4Bh,50h,48h ;keycodes for cursor keys
  71.  
  72.  
  73.     EIGHTY         db   80   ; to allow multiply by 80
  74.     SV_AX          dw   ?    ; temporary storage of AX register
  75.     SV_DX          dw   ?    ; temporary storage of DX register
  76.  
  77.     SCR_MAP        db   2000 dup  (0) ;screen map 80x25
  78.     SCR_OFF        dw   0         ; screen offset
  79.     P_LEN          dw   0         ; prompt length
  80.     FILL_CHAR      db   0         ; character to fill are with
  81.  
  82.  
  83.  
  84. ;=========================================
  85. ;= PART I:
  86. ;=
  87. ;= MOUSE, M_SET_ON(), M_SET_OFF()
  88. ;=
  89. ;= Used for the "keyboard emulation" mouse.  These are the mouse
  90. ;= routines used to make the highlighting bar (w/ @...prompt/menu
  91. ;= to) move when you move the mouse.
  92. ;=========================================
  93. ;
  94. MOUSE proc far
  95. ;
  96. ; determine which event occured, and branch accordingly
  97. ;
  98.     test ax,2           ; left button pressed?
  99.     jnz  LEFT           ; if yes, then go insert 'LB' into buffer
  100.     test ax,8           ; right button pressed?
  101.     jnz  RIGHT          ; if yes, then go insert 'RB' into buffer
  102.     test ax,32          ; center button pressed? (PC MOUSE)
  103.     jnz  CENTER         ; if yes, then go insert 'CB' into buffer
  104.  
  105. MOUSE0:
  106.     mov  ax,11               ; use mouse driver's function 11
  107.     int  51                  ; read mouse motion counters
  108.     mov  HFLAG,0             ; initialize sign flags
  109.     mov  VFLAG,2             ;
  110.     xor  al,al               ; zero AL for extended keycode
  111.     cmp  cx,0                ; horizontal count positive?
  112.     jge  MOUSE1              ; yes, then branch
  113.     inc  HFLAG               ; record negative condition
  114.     neg  cx                  ; convert negative to positive
  115.  
  116. MOUSE1:
  117.     cmp  dx,0                ; vertical count positive
  118.     jge  MOUSE2              ; yes, then branch
  119.     inc  VFLAG               ; record negative condition
  120.     neg  dx                  ; convert negative to positive
  121.  
  122. MOUSE2:
  123.     mov  bx,HFLAG            ; assume motion was horizontal
  124.     cmp  cx,dx               ; was assumption correct?
  125.     jae  HORIZ               ; yes, then branch
  126.     mov  bx,VFLAG            ; no, then correct it
  127.     dec  VCOUNT              ; decrement vertical delay count
  128.     jz   MOUSE3              ; continue if count is zero
  129.     jmp  GET_OUT
  130.  
  131. HORIZ:
  132.     dec  HCOUNT
  133.     jz   MOUSE3
  134.  
  135. GET_OUT:
  136.     ret
  137.  
  138. MOUSE3:
  139.     mov  HCOUNT,10
  140.     mov  VCOUNT,10           ; reset delay counter
  141.     mov  ah,KEYCODE[bx]      ; get keycode from table
  142.     call INSERT              ; insert it into keyboard buffer
  143.     jmp  RETURN
  144.  
  145. LEFT:
  146.     mov  ax,LB               ; load pre-defined 'LB' keycode 
  147.                              ; into buffer
  148.     call INSERT              ; insert it into buffer
  149.     jmp  RETURN
  150. RIGHT:
  151.     mov  ax,RB               ; load pre-defined 'RB' keycode
  152.                              ; into buffer
  153.     call INSERT              ; insert it into buffer
  154.     jmp  RETURN
  155.  
  156. CENTER:
  157.     mov  ax,CB               ; load pre-defined 'CB' keycode
  158.                              ; into buffer
  159.     call INSERT              ; insert it into buffer
  160.  
  161. RETURN:
  162.     ret
  163.  
  164. MOUSE endp
  165. ;
  166. ;
  167. ;
  168. ;****************************************
  169. ;** M_SET_ON() : routine to set up a function to be called upon
  170. ;**              mouse activity, using the mouse driver's 
  171. ;**              function 12.
  172. ;****************************************
  173. M_SET_ON proc far
  174.     push bp                  ; save everything as documented in
  175.     mov  bp,sp               ; Aut '86 Nantucket News or you
  176.     push ds                  ; will blow up!
  177.     push es                  ;
  178.     mov  ax,0                ; use function 0 of driver to see
  179.     int  33h                 ; if mouse and driver are installed
  180.     or   ax,ax               ; is there a mouse?
  181.     jne  OK                  ; yes, continue
  182.     mov  bx,0                ; return to Clipper a .F. to tell
  183.     push bx                  ; it that M_SET_ON() failed to set
  184.     call __retl              ; up the routine (extended interface)
  185.     jmp  DONE                ; go back to Clipper
  186.  
  187. OK:
  188.     mov  ax,15               ; use function 15 of mouse driver to
  189.     mov  cx,400              ; set the mouses sensitivity
  190.     mov  dx,800              ;
  191.     int  33h                 ;
  192.     mov  ax,seg MOUSE        ; tell function 12 where to find the
  193.     mov  es,ax               ; the mouse routine
  194.     mov  dx,offset MOUSE     ;
  195.     mov  ax,12               ; use function 12
  196.     mov  cx,0000000000101011b     ; set up the mask for buttons 
  197.                                   ; and cursor
  198.     int  33h               ; set it up!
  199.     mov  bx,1              ; return a .T. to Clipper to tell it
  200.     push bx                ; that the installation was successful
  201.     call __retl            ; (using Clipper's extended interface)
  202.  
  203. DONE:
  204.     pop  bx                  ; restore the stack or DIE!!!!
  205.     pop  es                  ;
  206.     pop  ds                  ;
  207.     pop  bp                  ;
  208.     ret                      ; exit and pray!!
  209. M_SET_ON endp
  210. ;
  211. ;
  212. ;
  213. ;***********************************************
  214. ;** M_SET_OFF() : routine to disable the mouse routine so that
  215. ;**               accidentally hitting the mouse won't cause the
  216. ;**               cursor keys to be inserted into the keyboard
  217. ;**               buffer
  218. ;***********************************************
  219. M_SET_OFF proc far
  220.     push bp             ; save these registers as usual
  221.     mov  bp,sp          ;
  222.     push ds             ; or DIE!!!!!
  223.     push es             ;
  224.     mov  ax,0           ;